import xarray as xr
ds = xr.open_mfdataset(f'../tests/data/m1_hello_schism/outputs/out2d_*.nc', concat_dim='time', combine="nested",
data_vars='minimal', coords='minimal', compat='override')
ds
<xarray.Dataset>
Dimensions: (time: 144, one: 1, nSCHISM_hgrid_node: 2639,
nSCHISM_hgrid_face: 4636,
nSCHISM_hgrid_edge: 7274,
nMaxSCHISM_hgrid_face_nodes: 4, two: 2)
Coordinates:
* time (time) datetime64[ns] 1999-12-31T16:20:00 ... 20...
SCHISM_hgrid_node_x (nSCHISM_hgrid_node) float64 dask.array<chunksize=(2639,), meta=np.ndarray>
SCHISM_hgrid_node_y (nSCHISM_hgrid_node) float64 dask.array<chunksize=(2639,), meta=np.ndarray>
SCHISM_hgrid_face_x (nSCHISM_hgrid_face) float64 dask.array<chunksize=(4636,), meta=np.ndarray>
SCHISM_hgrid_face_y (nSCHISM_hgrid_face) float64 dask.array<chunksize=(4636,), meta=np.ndarray>
SCHISM_hgrid_edge_x (nSCHISM_hgrid_edge) float64 dask.array<chunksize=(7274,), meta=np.ndarray>
SCHISM_hgrid_edge_y (nSCHISM_hgrid_edge) float64 dask.array<chunksize=(7274,), meta=np.ndarray>
Dimensions without coordinates: one, nSCHISM_hgrid_node, nSCHISM_hgrid_face,
nSCHISM_hgrid_edge,
nMaxSCHISM_hgrid_face_nodes, two
Data variables:
minimum_depth (one) float64 dask.array<chunksize=(1,), meta=np.ndarray>
SCHISM_hgrid (one) |S1 dask.array<chunksize=(1,), meta=np.ndarray>
depth (nSCHISM_hgrid_node) float32 dask.array<chunksize=(2639,), meta=np.ndarray>
bottom_index_node (nSCHISM_hgrid_node) int32 dask.array<chunksize=(2639,), meta=np.ndarray>
SCHISM_hgrid_face_nodes (nSCHISM_hgrid_face, nMaxSCHISM_hgrid_face_nodes) float64 dask.array<chunksize=(4636, 4), meta=np.ndarray>
SCHISM_hgrid_edge_nodes (nSCHISM_hgrid_edge, two) float64 dask.array<chunksize=(7274, 2), meta=np.ndarray>
dryFlagNode (time, nSCHISM_hgrid_node) float32 dask.array<chunksize=(72, 2639), meta=np.ndarray>
elevation (time, nSCHISM_hgrid_node) float32 dask.array<chunksize=(72, 2639), meta=np.ndarray>
depthAverageVelX (time, nSCHISM_hgrid_node) float32 dask.array<chunksize=(72, 2639), meta=np.ndarray>
depthAverageVelY (time, nSCHISM_hgrid_node) float32 dask.array<chunksize=(72, 2639), meta=np.ndarray>
dryFlagElement (time, nSCHISM_hgrid_face) float32 dask.array<chunksize=(72, 4636), meta=np.ndarray>
dryFlagSide (time, nSCHISM_hgrid_edge) float32 dask.array<chunksize=(72, 7274), meta=np.ndarray>array(['1999-12-31T16:20:00.000000000', '1999-12-31T16:40:00.000000000',
'1999-12-31T17:00:00.000000000', '1999-12-31T17:20:00.000000000',
'1999-12-31T17:40:00.000000000', '1999-12-31T18:00:00.000000000',
'1999-12-31T18:20:00.000000000', '1999-12-31T18:40:00.000000000',
'1999-12-31T19:00:00.000000000', '1999-12-31T19:20:00.000000000',
'1999-12-31T19:40:00.000000000', '1999-12-31T20:00:00.000000000',
'1999-12-31T20:20:00.000000000', '1999-12-31T20:40:00.000000000',
'1999-12-31T21:00:00.000000000', '1999-12-31T21:20:00.000000000',
'1999-12-31T21:40:00.000000000', '1999-12-31T22:00:00.000000000',
'1999-12-31T22:20:00.000000000', '1999-12-31T22:40:00.000000000',
'1999-12-31T23:00:00.000000000', '1999-12-31T23:20:00.000000000',
'1999-12-31T23:40:00.000000000', '2000-01-01T00:00:00.000000000',
'2000-01-01T00:20:00.000000000', '2000-01-01T00:40:00.000000000',
'2000-01-01T01:00:00.000000000', '2000-01-01T01:20:00.000000000',
'2000-01-01T01:40:00.000000000', '2000-01-01T02:00:00.000000000',
'2000-01-01T02:20:00.000000000', '2000-01-01T02:40:00.000000000',
'2000-01-01T03:00:00.000000000', '2000-01-01T03:20:00.000000000',
'2000-01-01T03:40:00.000000000', '2000-01-01T04:00:00.000000000',
'2000-01-01T04:20:00.000000000', '2000-01-01T04:40:00.000000000',
'2000-01-01T05:00:00.000000000', '2000-01-01T05:20:00.000000000',
'2000-01-01T05:40:00.000000000', '2000-01-01T06:00:00.000000000',
'2000-01-01T06:20:00.000000000', '2000-01-01T06:40:00.000000000',
'2000-01-01T07:00:00.000000000', '2000-01-01T07:20:00.000000000',
'2000-01-01T07:40:00.000000000', '2000-01-01T08:00:00.000000000',
'2000-01-01T08:20:00.000000000', '2000-01-01T08:40:00.000000000',
'2000-01-01T09:00:00.000000000', '2000-01-01T09:20:00.000000000',
'2000-01-01T09:40:00.000000000', '2000-01-01T10:00:00.000000000',
'2000-01-01T10:20:00.000000000', '2000-01-01T10:40:00.000000000',
'2000-01-01T11:00:00.000000000', '2000-01-01T11:20:00.000000000',
'2000-01-01T11:40:00.000000000', '2000-01-01T12:00:00.000000000',
'2000-01-01T12:20:00.000000000', '2000-01-01T12:40:00.000000000',
'2000-01-01T13:00:00.000000000', '2000-01-01T13:20:00.000000000',
'2000-01-01T13:40:00.000000000', '2000-01-01T14:00:00.000000000',
'2000-01-01T14:20:00.000000000', '2000-01-01T14:40:00.000000000',
'2000-01-01T15:00:00.000000000', '2000-01-01T15:20:00.000000000',
'2000-01-01T15:40:00.000000000', '2000-01-01T16:00:00.000000000',
'2000-01-01T16:20:00.000000000', '2000-01-01T16:40:00.000000000',
'2000-01-01T17:00:00.000000000', '2000-01-01T17:20:00.000000000',
'2000-01-01T17:40:00.000000000', '2000-01-01T18:00:00.000000000',
'2000-01-01T18:20:00.000000000', '2000-01-01T18:40:00.000000000',
'2000-01-01T19:00:00.000000000', '2000-01-01T19:20:00.000000000',
'2000-01-01T19:40:00.000000000', '2000-01-01T20:00:00.000000000',
'2000-01-01T20:20:00.000000000', '2000-01-01T20:40:00.000000000',
'2000-01-01T21:00:00.000000000', '2000-01-01T21:20:00.000000000',
'2000-01-01T21:40:00.000000000', '2000-01-01T22:00:00.000000000',
'2000-01-01T22:20:00.000000000', '2000-01-01T22:40:00.000000000',
'2000-01-01T23:00:00.000000000', '2000-01-01T23:20:00.000000000',
'2000-01-01T23:40:00.000000000', '2000-01-02T00:00:00.000000000',
'2000-01-02T00:20:00.000000000', '2000-01-02T00:40:00.000000000',
'2000-01-02T01:00:00.000000000', '2000-01-02T01:20:00.000000000',
'2000-01-02T01:40:00.000000000', '2000-01-02T02:00:00.000000000',
'2000-01-02T02:20:00.000000000', '2000-01-02T02:40:00.000000000',
'2000-01-02T03:00:00.000000000', '2000-01-02T03:20:00.000000000',
'2000-01-02T03:40:00.000000000', '2000-01-02T04:00:00.000000000',
'2000-01-02T04:20:00.000000000', '2000-01-02T04:40:00.000000000',
'2000-01-02T05:00:00.000000000', '2000-01-02T05:20:00.000000000',
'2000-01-02T05:40:00.000000000', '2000-01-02T06:00:00.000000000',
'2000-01-02T06:20:00.000000000', '2000-01-02T06:40:00.000000000',
'2000-01-02T07:00:00.000000000', '2000-01-02T07:20:00.000000000',
'2000-01-02T07:40:00.000000000', '2000-01-02T08:00:00.000000000',
'2000-01-02T08:20:00.000000000', '2000-01-02T08:40:00.000000000',
'2000-01-02T09:00:00.000000000', '2000-01-02T09:20:00.000000000',
'2000-01-02T09:40:00.000000000', '2000-01-02T10:00:00.000000000',
'2000-01-02T10:20:00.000000000', '2000-01-02T10:40:00.000000000',
'2000-01-02T11:00:00.000000000', '2000-01-02T11:20:00.000000000',
'2000-01-02T11:40:00.000000000', '2000-01-02T12:00:00.000000000',
'2000-01-02T12:20:00.000000000', '2000-01-02T12:40:00.000000000',
'2000-01-02T13:00:00.000000000', '2000-01-02T13:20:00.000000000',
'2000-01-02T13:40:00.000000000', '2000-01-02T14:00:00.000000000',
'2000-01-02T14:20:00.000000000', '2000-01-02T14:40:00.000000000',
'2000-01-02T15:00:00.000000000', '2000-01-02T15:20:00.000000000',
'2000-01-02T15:40:00.000000000', '2000-01-02T16:00:00.000000000'],
dtype='datetime64[ns]')
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
PandasIndex(DatetimeIndex(['1999-12-31 16:20:00', '1999-12-31 16:40:00',
'1999-12-31 17:00:00', '1999-12-31 17:20:00',
'1999-12-31 17:40:00', '1999-12-31 18:00:00',
'1999-12-31 18:20:00', '1999-12-31 18:40:00',
'1999-12-31 19:00:00', '1999-12-31 19:20:00',
...
'2000-01-02 13:00:00', '2000-01-02 13:20:00',
'2000-01-02 13:40:00', '2000-01-02 14:00:00',
'2000-01-02 14:20:00', '2000-01-02 14:40:00',
'2000-01-02 15:00:00', '2000-01-02 15:20:00',
'2000-01-02 15:40:00', '2000-01-02 16:00:00'],
dtype='datetime64[ns]', name='time', length=144, freq=None))from schimpy import schism_mesh
import numpy as np
import pandas as pd
import hvplot.xarray
import holoviews as hv
from holoviews import opts,dim
hv.extension('bokeh')
import panel as pn
pn.extension()
smesh = schism_mesh.read_mesh('../tests/data/m1_hello_schism/hgrid.gr3')
dfelems = pd.DataFrame(smesh.elems,columns=[0,1,2])
#dfelems
dfnodes = pd.DataFrame(smesh.nodes, columns=['x','y','z'])
#dfnodes
vmag = np.sqrt(ds.depthAverageVelX**2+ds.depthAverageVelY**2)
vangle = np.arctan2(ds.depthAverageVelY,ds.depthAverageVelX)
vel = xr.Dataset({'mag':vmag,'angle': vangle})
vel
<xarray.Dataset>
Dimensions: (time: 144, nSCHISM_hgrid_node: 2639)
Coordinates:
* time (time) datetime64[ns] 1999-12-31T16:20:00 ... 2000-0...
SCHISM_hgrid_node_x (nSCHISM_hgrid_node) float64 dask.array<chunksize=(2639,), meta=np.ndarray>
SCHISM_hgrid_node_y (nSCHISM_hgrid_node) float64 dask.array<chunksize=(2639,), meta=np.ndarray>
Dimensions without coordinates: nSCHISM_hgrid_node
Data variables:
mag (time, nSCHISM_hgrid_node) float32 dask.array<chunksize=(72, 2639), meta=np.ndarray>
angle (time, nSCHISM_hgrid_node) float32 dask.array<chunksize=(72, 2639), meta=np.ndarray>array(['1999-12-31T16:20:00.000000000', '1999-12-31T16:40:00.000000000',
'1999-12-31T17:00:00.000000000', '1999-12-31T17:20:00.000000000',
'1999-12-31T17:40:00.000000000', '1999-12-31T18:00:00.000000000',
'1999-12-31T18:20:00.000000000', '1999-12-31T18:40:00.000000000',
'1999-12-31T19:00:00.000000000', '1999-12-31T19:20:00.000000000',
'1999-12-31T19:40:00.000000000', '1999-12-31T20:00:00.000000000',
'1999-12-31T20:20:00.000000000', '1999-12-31T20:40:00.000000000',
'1999-12-31T21:00:00.000000000', '1999-12-31T21:20:00.000000000',
'1999-12-31T21:40:00.000000000', '1999-12-31T22:00:00.000000000',
'1999-12-31T22:20:00.000000000', '1999-12-31T22:40:00.000000000',
'1999-12-31T23:00:00.000000000', '1999-12-31T23:20:00.000000000',
'1999-12-31T23:40:00.000000000', '2000-01-01T00:00:00.000000000',
'2000-01-01T00:20:00.000000000', '2000-01-01T00:40:00.000000000',
'2000-01-01T01:00:00.000000000', '2000-01-01T01:20:00.000000000',
'2000-01-01T01:40:00.000000000', '2000-01-01T02:00:00.000000000',
'2000-01-01T02:20:00.000000000', '2000-01-01T02:40:00.000000000',
'2000-01-01T03:00:00.000000000', '2000-01-01T03:20:00.000000000',
'2000-01-01T03:40:00.000000000', '2000-01-01T04:00:00.000000000',
'2000-01-01T04:20:00.000000000', '2000-01-01T04:40:00.000000000',
'2000-01-01T05:00:00.000000000', '2000-01-01T05:20:00.000000000',
'2000-01-01T05:40:00.000000000', '2000-01-01T06:00:00.000000000',
'2000-01-01T06:20:00.000000000', '2000-01-01T06:40:00.000000000',
'2000-01-01T07:00:00.000000000', '2000-01-01T07:20:00.000000000',
'2000-01-01T07:40:00.000000000', '2000-01-01T08:00:00.000000000',
'2000-01-01T08:20:00.000000000', '2000-01-01T08:40:00.000000000',
'2000-01-01T09:00:00.000000000', '2000-01-01T09:20:00.000000000',
'2000-01-01T09:40:00.000000000', '2000-01-01T10:00:00.000000000',
'2000-01-01T10:20:00.000000000', '2000-01-01T10:40:00.000000000',
'2000-01-01T11:00:00.000000000', '2000-01-01T11:20:00.000000000',
'2000-01-01T11:40:00.000000000', '2000-01-01T12:00:00.000000000',
'2000-01-01T12:20:00.000000000', '2000-01-01T12:40:00.000000000',
'2000-01-01T13:00:00.000000000', '2000-01-01T13:20:00.000000000',
'2000-01-01T13:40:00.000000000', '2000-01-01T14:00:00.000000000',
'2000-01-01T14:20:00.000000000', '2000-01-01T14:40:00.000000000',
'2000-01-01T15:00:00.000000000', '2000-01-01T15:20:00.000000000',
'2000-01-01T15:40:00.000000000', '2000-01-01T16:00:00.000000000',
'2000-01-01T16:20:00.000000000', '2000-01-01T16:40:00.000000000',
'2000-01-01T17:00:00.000000000', '2000-01-01T17:20:00.000000000',
'2000-01-01T17:40:00.000000000', '2000-01-01T18:00:00.000000000',
'2000-01-01T18:20:00.000000000', '2000-01-01T18:40:00.000000000',
'2000-01-01T19:00:00.000000000', '2000-01-01T19:20:00.000000000',
'2000-01-01T19:40:00.000000000', '2000-01-01T20:00:00.000000000',
'2000-01-01T20:20:00.000000000', '2000-01-01T20:40:00.000000000',
'2000-01-01T21:00:00.000000000', '2000-01-01T21:20:00.000000000',
'2000-01-01T21:40:00.000000000', '2000-01-01T22:00:00.000000000',
'2000-01-01T22:20:00.000000000', '2000-01-01T22:40:00.000000000',
'2000-01-01T23:00:00.000000000', '2000-01-01T23:20:00.000000000',
'2000-01-01T23:40:00.000000000', '2000-01-02T00:00:00.000000000',
'2000-01-02T00:20:00.000000000', '2000-01-02T00:40:00.000000000',
'2000-01-02T01:00:00.000000000', '2000-01-02T01:20:00.000000000',
'2000-01-02T01:40:00.000000000', '2000-01-02T02:00:00.000000000',
'2000-01-02T02:20:00.000000000', '2000-01-02T02:40:00.000000000',
'2000-01-02T03:00:00.000000000', '2000-01-02T03:20:00.000000000',
'2000-01-02T03:40:00.000000000', '2000-01-02T04:00:00.000000000',
'2000-01-02T04:20:00.000000000', '2000-01-02T04:40:00.000000000',
'2000-01-02T05:00:00.000000000', '2000-01-02T05:20:00.000000000',
'2000-01-02T05:40:00.000000000', '2000-01-02T06:00:00.000000000',
'2000-01-02T06:20:00.000000000', '2000-01-02T06:40:00.000000000',
'2000-01-02T07:00:00.000000000', '2000-01-02T07:20:00.000000000',
'2000-01-02T07:40:00.000000000', '2000-01-02T08:00:00.000000000',
'2000-01-02T08:20:00.000000000', '2000-01-02T08:40:00.000000000',
'2000-01-02T09:00:00.000000000', '2000-01-02T09:20:00.000000000',
'2000-01-02T09:40:00.000000000', '2000-01-02T10:00:00.000000000',
'2000-01-02T10:20:00.000000000', '2000-01-02T10:40:00.000000000',
'2000-01-02T11:00:00.000000000', '2000-01-02T11:20:00.000000000',
'2000-01-02T11:40:00.000000000', '2000-01-02T12:00:00.000000000',
'2000-01-02T12:20:00.000000000', '2000-01-02T12:40:00.000000000',
'2000-01-02T13:00:00.000000000', '2000-01-02T13:20:00.000000000',
'2000-01-02T13:40:00.000000000', '2000-01-02T14:00:00.000000000',
'2000-01-02T14:20:00.000000000', '2000-01-02T14:40:00.000000000',
'2000-01-02T15:00:00.000000000', '2000-01-02T15:20:00.000000000',
'2000-01-02T15:40:00.000000000', '2000-01-02T16:00:00.000000000'],
dtype='datetime64[ns]')
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
PandasIndex(DatetimeIndex(['1999-12-31 16:20:00', '1999-12-31 16:40:00',
'1999-12-31 17:00:00', '1999-12-31 17:20:00',
'1999-12-31 17:40:00', '1999-12-31 18:00:00',
'1999-12-31 18:20:00', '1999-12-31 18:40:00',
'1999-12-31 19:00:00', '1999-12-31 19:20:00',
...
'2000-01-02 13:00:00', '2000-01-02 13:20:00',
'2000-01-02 13:40:00', '2000-01-02 14:00:00',
'2000-01-02 14:20:00', '2000-01-02 14:40:00',
'2000-01-02 15:00:00', '2000-01-02 15:20:00',
'2000-01-02 15:40:00', '2000-01-02 16:00:00'],
dtype='datetime64[ns]', name='time', length=144, freq=None))The length of the vectors needs to be scaled depending upon the zoom in and magnitude
def velocity_field(time, vector_size=1):
data = vel.isel(time=time)
vf = hv.VectorField((vel.coords['SCHISM_hgrid_node_x'],vel.coords['SCHISM_hgrid_node_y'],data.angle, data.mag))
vf.opts(opts.VectorField(pivot='tip', color=dim('Magnitude'), magnitude=dim('Magnitude').norm()*2000*vector_size, rescale_lengths=False))
return vf.opts(width=600)
dmap = hv.DynamicMap(velocity_field,kdims=['time','vector_size']).opts(title='Velocity Vectors')
hv.output(widget_location='top')
dmap = dmap.redim.range(time=(0,len(vel.time)-1)).redim.values(vector_size=[0.25,0.5,0.75,1,2,5,10,20])
dash = pn.Row(dmap)
dash.servable('Velocity Vector Animations')#.show()